/**
 * 
 */
var process = {
	id : 'process-panel',
	title : '流程视图',
	layout : 'border',
	defaults : {
		
		bodyStyle : 'padding:15px'
	},
	items : [  {
		tbar: [{xtype:'button',width:50,text:'返回',iconCls: 'return',handler:returnToProcessList}],
		region : 'center',
		border : false,
		autoScroll:true,
		contentEl : 'processCanvas'
	} ]
};

function returnToProcessList(){
	
	  Ext.getCmp('content-panel').layout.setActiveItem('process-list-panel');
	  showProcessList();
}
var processid;
var pText;
var functionStore = new Ext.data.Store({
	proxy : new Ext.data.HttpProxy({
		url : 'showFunction.action?method=showFunction',
		method : 'post'
	}),
	reader : new Ext.data.JsonReader({
		root : "function",
		totalProperty : "totalFunction",
		id:"id"
    }, [ {
		name : 'id'
	}, {
		name : 'fileId'
	}, {
		name : 'enName'
	},{
		name : 'cnName'
	},{
		name : 'description'
	}])
});
function showProcessContent(cid,text) {
	
    processid=cid;
    pText=text;
    functionStore.load({ 
    	params : {
			cid : cid
		},
		callback: function(r, options, success) { 
		if (success == false) {  
		alert("加载数据失败，无对应数据或者系统出现异常！"); 
		}else{ 
			var canvas=document.getElementById('processCanvas');
			var ctx=canvas.getContext('2d');
			 drawProcessModel(300,200,ctx,functionStore,text,canvas);
			
			}
		}
		});
   }
function drawProcessModel(startx,starty,ctx,functionStore,text,canvas){
	 ctx.restore();
	 ctx.clearRect(0, 0, 800, 800);
	 ctx.save();
	 ctx.translate(startx, starty);
	 var fAmount=functionStore.getCount();
	
	 var gradient = ctx.createLinearGradient(0, 0, 0, 50);
	 gradient.addColorStop(0, 'rgb(154, 205, 50)');
	 gradient.addColorStop(1, 'rgb(255,255,240)');
	 ctx.fillStyle = gradient;
	 ctx.fillRect( 0, 0, 100, 50); //渐变的背景色
	 
	 ctx.strokeStyle = '#000000'; 
	 ctx.beginPath(); 
	 ctx.lineWidth = 1;
	 ctx.rect(0.5,0.5, 100, 50);
	 ctx.stroke();              //黑边框
	 
	 var processImage=new Image();
	 processImage.onload=function(){
	 ctx.drawImage(processImage,10,12,16,16);
	 };
	 processImage.src='images/modelUnit/function/process.gif';
	 
	 ctx.fillStyle ="black";
	 ctx.font = "10pt 宋体";
	 ctx.fillText(text,30,25,70); //标题栏
	 
	
	 var functionImg=new Image();
	 functionImg.onload=function(){
     for (var i=0;i<fAmount;i++){
    	    x=parseInt(-150*Math.cos(i*Math.PI*2/fAmount));
    	    if (x>100) x=1.2*x;
    	    y=parseInt(-150*Math.sin(i*Math.PI*2/fAmount));
    	     gradient = ctx.createLinearGradient(x, y, 0, 50);
    		 gradient.addColorStop(0, 'rgb(230, 230, 250)');
    		 gradient.addColorStop(1, 'rgb(255,255,240)');
    		 ctx.fillStyle = gradient;
    		 ctx.fillRect( x, y, 100, 50); //渐变的背景色
    		
    		 ctx.lineWidth = 1;
    		 ctx.strokeStyle = '#000000'; 
    		 ctx.beginPath(); 
    		
    		 ctx.rect(x-0.5,y-0.5, 100, 50);
    		 ctx.stroke();              //黑边框
    		 
			ctx.drawImage(functionImg,x+10,12+y,16,16);
			var record=functionStore.getAt(i);	
			ctx.fillStyle ="black";
			ctx.font = "10pt Arial ";
			ctx.fillText(record.get('cnName'),x+30,y+25,70);
			ctx.fillText('['+record.get('enName')+']',x,y+45,100);
			drawLine(x+50,y+25,50,25,ctx,100,50);
		 }
        canvas.onclick = onMouseClick;     
	 };
	 functionImg.src='images/modelUnit/function/function_point.gif';
	 }
function onMouseClick(event) {
	 var fAmount=functionStore.getCount();
	 var i=0;
	 var x=event.layerX-300;
	 var y=event.layerY-200;
	 if (x/1.2>100) x=x/1.2;
	 while (i<fAmount){
     
     if (x>-150*Math.cos(i*Math.PI*2/fAmount)
    	 && x<-150*Math.cos(i*Math.PI*2/fAmount)+100
         && y>-150*Math.sin(i*Math.PI*2/fAmount)
         && y<-150*Math.sin(i*Math.PI*2/fAmount)+50)
    {
    	
    	 authenticate(functionStore.getAt(i).get('fileId'),'read',function(){
   	       Ext.getCmp('content-panel').layout.setActiveItem('functionpoint-panel');
   	       showFunctionContent(functionStore.getAt(i).get('id'),functionStore.getAt(i).get('cnName'),processid,pText);
        
      	 });
      	 break;
     }
      i++;
	 }
}  


